package com.zl.basic.CommonUtil;

import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * User: zl email:c3tc3tc3t@126.com Date: 14-2-24 Time: 下午1:59 安全相关工具类 对用户密码进行md5加密
 */
public class SecurityUtil {
  public static String md5(String password) {
    String result = null;
    try {
      MessageDigest md = MessageDigest.getInstance("md5");
      md.update(password.getBytes(), 0, password.length());
      result = new BigInteger(1, md.digest()).toString(16);
    } catch (NoSuchAlgorithmException e) {
      e.printStackTrace();
    }
    return result;
  }
	//加盐值md5
	public static String md5(String username,String password) {
		String result = null;
		try {
			MessageDigest md = MessageDigest.getInstance("md5");

			md.update((username).getBytes(), 0, username.length());
			md.update((password).getBytes(), 0, password.length());
			result = new BigInteger(1, md.digest()).toString(16);
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return result;
	}
}
